package com.moli.iov.task.service.impl;

import com.moli.iov.task.model.BlueToothPassDto;
import com.moli.iov.task.remoting.op.reponse.VehiclePushResponseHandler;
import com.moli.iov.task.service.IBlueToothPassTaskService;
import com.moli.iov.util.JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * @ClassName BlueToothPassTaskServiceImpl
 * @Description TODO
 * @Author 李伟松
 * @CreateDate 2019-04-28 上午 10:52
 * @UpdateDate 2019-04-28 上午 10:52
 * @Version 1.0
 */
@Service("blueToothPassTaskService")
@Slf4j
public class BlueToothPassTaskServiceImpl implements IBlueToothPassTaskService {


    @Value("${op_bluetooth_pass_push_url}")
    private String url;

    @Resource
    VehiclePushResponseHandler vehiclePushResponseHandler;

    @Override
    public void pushBlueToothPass(BlueToothPassDto dto) {
        log.info("推送蓝牙密码，{}",dto);
        if (dto != null && !StringUtils.isEmpty(dto.getBluetoothPwd()) && !StringUtils.isEmpty(dto.getVin())) {
            String data = JsonUtils.toJson(dto);
            try {
                vehiclePushResponseHandler.push(url, data);
                log.info("推送蓝牙密码成功，{}",dto);
            } catch (IOException e) {
                log.error("推送蓝牙密码失败，{}",dto);
//                e.printStackTrace();
            }
        }
    }
}
